<?php

define('IN_TT', TRUE);
//define('TT_ROOT', dirname(__FILE__).'/');
define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());

//unset($_ENV);
require 'data/config.inc.php';
require 'model/BaseModel.php';
require 'control/BaseCtrl.php';

///////////////////////////////////////



$_GET		= daddslashes($_GET, 1, TRUE);
$_POST		= daddslashes($_POST, 1, TRUE);
$_COOKIE	= daddslashes($_COOKIE, 1, TRUE);
$_SERVER	= daddslashes($_SERVER);
$_FILES		= daddslashes($_FILES);
$_REQUEST	= daddslashes($_REQUEST, 1, TRUE);

$m = getgpc('m');	// module indentifier
$a = getgpc('a');

if(in_array($m, array('User','Message') ))
{
	require "control/".$m."Ctrl.php";
	$classname = $m."Ctrl";
	$ctrl = new $classname();
	$method = "on".$a;	// onAction();
	if (method_exists($ctrl, $method))
	{
		$data = $ctrl->$method();
		exit();
	}
	else
	{
		exit("Action not found!");
	}
}
else
{
	exit("Module not found!");
}
//
//$c = new UserCtrl();
//$c->onadd();


function daddslashes($string, $force = 0, $strip = FALSE) {
	if(!MAGIC_QUOTES_GPC || $force) {
		if(is_array($string)) {
			foreach($string as $key => $val) {
				$string[$key] = daddslashes($val, $force, $strip);
			}
		} else {
			$string = addslashes($strip ? stripslashes($string) : $string);
		}
	}
	return $string;
}

function debug_echo($str)
{
	echo $str;
}

//function getgpc($k, $var='R') {
//	switch($var) {
//		case 'G': $var = &$_GET; break;
//		case 'P': $var = &$_POST; break;
//		case 'C': $var = &$_COOKIE; break;
//		case 'R': $var = &$_REQUEST; break;
//	}
//	return isset($var[$k]) ? $var[$k] : NULL;
//}


?>

